package com.example.product.service.impl;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.crypto.SecureUtil;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.product.entity.Account;
import com.example.product.entity.Notice;
import com.example.product.exception.CustomException;
import com.example.product.mapper.NoticeMapper;
import com.example.product.service.NoticeService;
import com.example.product.util.Result;
import com.example.product.util.TokenUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;

/**
 * 管理员业务处理
 **/
@Service
@Transactional
public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice> implements NoticeService {

    @Autowired
    private TokenUtil tokenUtil;

    @Autowired
    private NoticeMapper noticeMapper;


//    private Account convertNoticeToAccount(Notice notice) {
//        Account account = new Account();
//        account.setId(notice.getId());
//        account.setUsername(notice.getUsername());
//        account.setName(notice.getName());
//        account.setRole(notice.getRole());
//        account.setImg(notice.getImg());
//        return account;
//    }

    @Override
    /**
     * 新增
     */
    public void add(Notice notice) {
        notice.setTime(DateUtil.now()); //默认当前发布时间的最新的时间
        noticeMapper.insert(notice);
    }

    /**
     * 删除
     */
    @Override
    public void deleteById(Integer id) {
        noticeMapper.deleteById(id);
    }

    @Override
    public boolean saveBatch(Collection<Notice> entityList, int batchSize) {
        return false;
    }

    @Override
    public boolean saveOrUpdateBatch(Collection<Notice> entityList, int batchSize) {
        return false;
    }

    /**
     * 修改
     */
    @Override
    public boolean updateById(Notice notice) {
        noticeMapper.updateById(notice);
        return false;
    }

    @Override
    public boolean updateBatchById(Collection<Notice> entityList, int batchSize) {
        return false;
    }

    @Override
    public boolean saveOrUpdate(Notice entity) {
        return false;
    }

    @Override
    public Notice getOne(Wrapper<Notice> queryWrapper, boolean throwEx) {
        return null;
    }

    @Override
    public Optional<Notice> getOneOpt(Wrapper<Notice> queryWrapper, boolean throwEx) {
        return Optional.empty();
    }

    @Override
    public Map<String, Object> getMap(Wrapper<Notice> queryWrapper) {
        return null;
    }

    @Override
    public <V> V getObj(Wrapper<Notice> queryWrapper, Function<? super Object, V> mapper) {
        return null;
    }

    @Override
    public NoticeMapper getBaseMapper() {
        return null;
    }

    @Override
    public Class<Notice> getEntityClass() {
        return null;
    }

    /**
     * 根据ID查询
     */
    @Override
    public Notice selectById(Integer id) {
        return noticeMapper.selectById(id);
    }

    /**
     * 查询所有
     */
    @Override
    public List<Notice> selectAll(Notice notice) {
        return noticeMapper.selectAll(notice);
    }

    /**
     * 分页查询
     */
    @Override
    public PageInfo<Notice> selectPage(Notice notice, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Notice> list = noticeMapper.selectAll(notice);
        return PageInfo.of(list);
    }


}